package com.android.demos.module.appbarstyle.adpater;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aaron.android.framework.base.widget.recycleview.BaseRecycleViewAdapter;
import com.aaron.android.framework.base.widget.recycleview.BaseRecycleViewHolder;
import com.aaron.android.framework.base.widget.recycleview.ItemTouchHelperAdapter;
import com.android.demos.R;
import com.soybean.framework.common.StringUtils;

/**
 * Created on 16/5/4.
 *
 * @author aaron.huang
 * @version 1.0.0
 */
public class AppBarStyleRecyclerAdapter extends BaseRecycleViewAdapter<AppBarStyleRecyclerAdapter.AppBarStyleRecyclerViewHolder, String> implements ItemTouchHelperAdapter{
    public AppBarStyleRecyclerAdapter(Context context) {
        super(context);
    }

    @Override
    protected AppBarStyleRecyclerViewHolder createViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.main_recycler_item, parent, false);
        return new AppBarStyleRecyclerViewHolder(view);
    }

    @Override
    public boolean onItemMove(int fromPosition, int toPosition) {
        notifyItemMoved(fromPosition, toPosition);
        return true;
    }

    @Override
    public void onItemDismiss(int position) {
        notifyItemRemoved(position);
    }

    @Override
    public void onItemMoveFinish() {

    }

    class AppBarStyleRecyclerViewHolder extends BaseRecycleViewHolder<String> {
        private TextView mTitleTextView;
        @Override
        public void bindViews(String object) {
            if (StringUtils.isEmpty(object)) {
                return;
            }
            mTitleTextView.setText(object);
        }

        public AppBarStyleRecyclerViewHolder(View itemView) {
            super(itemView);
            mTitleTextView = (TextView) itemView.findViewById(R.id.text_view_main_item);
        }
    }
}
